#include <iostream>
#include "Controller.h"

namespace GASPUMP
{

Controller::Controller(void)
{
	crd = new cardreader();
	flpmp = new fuelpump();
	flslct = new FuelSelector();
	kpd = new Keypad();
	lcd = new LCDDisplay();
	rcp = new ReceiptPrinter() ;
	cntrl = this;
}

void Controller::userloop ( void )
{
	    kpd->ON();
		lcd->ON();
		flpmp->ON();
		flslct->ON();
		rcp->ON();
		m_opmode = true;
		//int ch;

	while(m_opmode == true)
	{
		try
		{
		*crd=lcd->LCD_operating_Menu( cntrl );
		if (m_opmode == true)
		{
			int Grade = lcd->LCD_Select_Grade();
			cout << flslct->fuelGrade(Grade) << endl;
			lcd->LCD_PumpFuel();			
			flpmp->Fuelling();
			_sleep( 2500 );
			cout << "\n";
			rcp->printReceipt();
			_sleep( 2500 );
			break;
		}
		else
			break;
		/*cout << "Enter 1 to ";
		cin >> ch;

		if(ch==1)
			m_opmode = true;
		else
			m_opmode = false;*/
		}
		catch(LCDError errnum)
		{
			std::cout << "A menu error has occurred: " << errnum.getLCDError().c_str() << endl;
		}
	}
}

void Controller::maintloop()
{
	    kpd->OFF();
		lcd->ON();
		flpmp->OFF();
		flslct->OFF();
		m_opmode=true;
		while(m_opmode)

	{
		lcd->LCD_Maintain_Menu();
		m_opmode= false;

	}
}


void Controller::resuploop (void)
{
	    kpd->OFF();
		lcd->ON();
		flpmp->OFF();
		flslct->OFF();
		m_opmode=true;
		while(m_opmode)
	{
		lcd->LCD_RrSup_Menu();
			m_opmode=false;


	}
}


Controller::~Controller(void)
{
	    
}

}